package net.toocruel.iqismart.web.controller.admin;

import net.toocruel.iqismart.entity.setting.Setting;
import net.toocruel.iqismart.service.core.EmailService;
import net.toocruel.iqismart.web.controller.base.AbstractBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.mail.MessagingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Description
 * @Auther sty
 * @createTime 2018/4/28 上午11:55
 */
@Controller
@RequestMapping("admin/tools")
public class AdminToolsController extends AbstractBaseController {

    @Autowired
    private EmailService  emailService;

    @RequestMapping("sendTestEmail")
    @ResponseBody
    public String sendTestEmail(HttpServletRequest request, HttpServletResponse response,String sendTo,String content) throws MessagingException {
        emailService.send(sendTo,Setting.SETTING.getWebsite().getName()+"测试邮件",content);

//        // 简单邮件信息类
//        MimeMessageHelper mimeMessageHelper;
//        MimeMessage mimeMessage = mailSender.createMimeMessage();
//        mimeMessageHelper = new MimeMessageHelper(mimeMessage, true, "UTF-8");
//        mimeMessageHelper.setFrom(new InternetAddress(Setting.SETTING.getEmail().getFromName()+" <"+Setting.SETTING.getEmail().getFromAddress()+">"));
//        mimeMessageHelper.setTo(sendTo);
//        mimeMessageHelper.setSubject(Setting.SETTING.getWebsite().getName()+"测试邮件");
//        mimeMessageHelper.setText(content, true);
//        mimeMessageHelper.setSentDate(new Date());
//        mailSender.send(mimeMessage);

        return "ok";
    }
}
